export type Feature = 'chat' | 'ai_dialog' | 'voice' | 'video' | 'theme' | 'exhibition' | 'all'

type RoleLike = { role?: string; rolename?: string } | null | undefined

export function isAdmin(user?: RoleLike): boolean {
  if (!user) return false
  return user.role === 'admin' || user.rolename === '管理员'
}

export function canUseFeature(roleInput: string | undefined, feature: Feature): boolean {
  const role = roleInput === 'admin' ? 'admin' : 'user'
  // 管理员可用所有功能
  if (role === 'admin') return true
  // 普通用户仅允许聊天与AI对话
  return feature === 'chat' || feature === 'ai_dialog'
}